package com.example.Controller;

import com.example.Service.Impl.ResourcesServiceImpl;
import com.example.Service.ResourcesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

/**
 *
 */
@Controller
@Api(tags = "资源模块")
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    ResourcesService resourcesService;
    @Autowired
    ResourcesServiceImpl service;
    @Autowired
    UserInfoController userInfoController;

    @PostMapping("/Input")
    @ResponseBody
    @ApiOperation(value = "单文件上传功能")
    public boolean input(MultipartFile file, String account) {

        //如果文件为空，那么返回false
        if (file.isEmpty()) {
            return false;
        }
        return resourcesService.InputUrl(file, account);
    }


    /**
     * @param account  账号
     * @return 读取的文件信息
     */
    @GetMapping("/GetUrl")
    @ApiOperation(value = "读取总目录的html文件")
    @ResponseBody
    public List<String> read(String account) {
        return service.getUrl(account);
    }

    @PostMapping("/GetUrls")
    @ApiOperation(value = "根据联系人来读取对应的聊天记录")
    @ResponseBody
    public String read(String account, String UserName, String OtherName) {
        return service.getUrl(account).get(0) + "/" + UserName + "/" + OtherName + ".html";
    }

    @PostMapping("/files")
    @ResponseBody
    @ApiOperation(value = "多文件上传功能")
    public boolean files(MultipartFile[] file, String account) {
        if (file.length == 0) {
            return false;
        }
        return resourcesService.InputUrl(file, account);
    }
    /**
     * @param account 账号
     * @param fileName 上传的文件夹名
     * @param userName 用户的微信名
     * @return 查询到的图片地址集合
     */
    @PostMapping("/getImg")
    @ResponseBody
    @ApiOperation(value = "拿取图片功能")
    public List<String> getImg(String account,String fileName,String userName){
        //返回所有图片路径
        return service.getImg(account,fileName,userName);
    }
    /**
     * @param account 账号
     * @param fileName 上传的文件夹名
     * @param userName 用户的微信名
     * @return 查询到的图片地址集合
     */
    @PostMapping("/getDocx")
    @ResponseBody
    @ApiOperation(value = "拿取文档功能")
    public List<String> getDocx(String account,String fileName,String userName){
        return service.getDocx(account,fileName,userName);
    }
}
